<template>
  <div class="login-container">
    <div class="login-box">
      <h2>医疗报销系统</h2>
      <div class="login-form">
        <div class="form-item">
          <input type="text" v-model="username" placeholder="用户名" />
        </div>
        <div class="form-item">
          <input type="password" v-model="password" placeholder="密码" />
        </div>
        
        <div class="role-selection">
          <h3>请选择登录身份</h3>
          <div class="role-options">
            <div class="role-option" :class="{ active: role === 'admin' }" @click="selectRole('admin')">
              <div class="radio-button" :class="{ checked: role === 'admin' }"></div>
              <span>医保数据维护部门</span>
            </div>
            <div class="role-option" :class="{ active: role === 'reimbursement' }" @click="selectRole('reimbursement')">
              <div class="radio-button" :class="{ checked: role === 'reimbursement' }"></div>
              <span>医保报销</span>
            </div>
            <div class="role-option" :class="{ active: role === 'hospital' }" @click="selectRole('hospital')">
              <div class="radio-button" :class="{ checked: role === 'hospital' }"></div>
              <span>医院</span>
            </div>
          </div>
        </div>
        
        <div class="form-item">
          <button class="login-button" @click="handleLogin">登录</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
// 不需要导入背景图片，直接在CSS中使用

const router = useRouter()
const username = ref('')
const password = ref('')
const role = ref('reimbursement') // 默认选择医保报销身份

const selectRole = (selectedRole) => {
  role.value = selectedRole
}

const handleLogin = () => {
  if (!username.value || !password.value) {
    alert('请输入用户名和密码')
    return
  }
  
  if (!role.value) {
    alert('请选择登录身份')
    return
  }
  
  // 模拟登录成功
  localStorage.setItem('token', 'demo-token')
  localStorage.setItem('userRole', role.value) // 保存用户角色
  
  // 根据不同角色跳转到不同页面
  if (role.value === 'admin') {
    router.push('/admin')
  } else if (role.value === 'reimbursement') {
    router.push('/reimbursement')
  } else if (role.value === 'hospital') {
    router.push('/hospital')
  } else {
    router.push('/home')
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url('~@/assets/login.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.login-box {
  width: 400px;
  padding: 30px;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
  text-align: center;
  backdrop-filter: blur(5px);
}

.login-box h2 {
  margin-bottom: 20px;
  color: #409EFF;
}

.login-form {
  text-align: left;
}

.form-item {
  margin-bottom: 20px;
}

.form-item input {
  width: 100%;
  padding: 12px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 14px;
}

.login-button {
  width: 100%;
  padding: 12px;
  background-color: #409EFF;
  border: none;
  border-radius: 4px;
  color: white;
  font-size: 14px;
  cursor: pointer;
}

.login-button:hover {
  background-color: #66b1ff;
}

/* 角色选择样式 */
.role-selection {
  margin-bottom: 20px;
}

.role-selection h3 {
  margin-bottom: 12px;
  font-size: 16px;
  font-weight: 500;
  color: #606266;
}

.role-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.role-option {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.role-option:hover {
  background-color: rgba(64, 158, 255, 0.1);
}

.role-option.active {
  background-color: rgba(64, 158, 255, 0.1);
}

.radio-button {
  width: 16px;
  height: 16px;
  border: 2px solid #dcdfe6;
  border-radius: 50%;
  margin-right: 10px;
  position: relative;
  transition: all 0.3s;
}

.radio-button.checked {
  border-color: #409EFF;
}

.radio-button.checked:after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  background-color: #409EFF;
  border-radius: 50%;
}

.role-option span {
  font-size: 14px;
  color: #606266;
}
</style> 